package com.lcp.ui;


import com.lcp.core.ControlledStage;
import com.lcp.utils.CommonUtil;
import com.lcp.utils.R;
import javafx.beans.value.ObservableValue;
import javafx.concurrent.Worker;
import javafx.fxml.FXML;
import javafx.fxml.Initializable;
import javafx.scene.layout.AnchorPane;
import javafx.scene.layout.HBox;
import javafx.scene.web.WebEngine;
import javafx.scene.web.WebView;
import netscape.javascript.JSObject;

import java.net.URISyntaxException;
import java.net.URL;
import java.util.ResourceBundle;

public class Menuview1Controller extends StageController implements ControlledStage, Initializable {

    private StageController stageController;
    @FXML
    private AnchorPane InfoPage;
    @FXML
    private HBox jfxTablePane;
    @FXML
    public WebView centerWebView;



    @Override
    public void setStageController(StageController stageController) {
        this.stageController = stageController;
    }

    @Override
    public void initialize(URL location, ResourceBundle resources) {
        MainController.initContentViewFrame(jfxTablePane);
        centerWebView.prefWidthProperty().bind(jfxTablePane.widthProperty());
        centerWebView.prefHeightProperty().bind(jfxTablePane.heightProperty());
        centerWebView.setContextMenuEnabled(false);
        WebEngine webEngine = initCenterWebView(centerWebView, R.menuviewUrl1);
        webEngine.getLoadWorker().stateProperty().addListener((ObservableValue<? extends Worker.State> ov, Worker.State oldState, Worker.State newState) -> {
            //判断页面是否加载完毕
            if(newState == Worker.State.SUCCEEDED) {
                System.out.println("SUCCEEDED");
                JSObject win = (JSObject) webEngine.executeScript("window");
                win.setMember("javaConnector",javaConnector);
                try {
                    String dxfContent = CommonUtil.getDXFDATA();
                    webEngine.executeScript("initAndDrawPic("+dxfContent+")");
                } catch (URISyntaxException e) {
                    e.printStackTrace();
                }
            }
        });

    }
}
